package me.zhengjie.modules.web.service.course.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import me.zhengjie.constant.ConstantUtils;
import me.zhengjie.modules.system.domain.CourseClock;
import me.zhengjie.modules.system.domain.CourseInfoClockSource;
import me.zhengjie.modules.web.service.course.ICourseClockWebService;
import me.zhengjie.modules.web.service.mybatisplus.ICourseClockPlusService;
import me.zhengjie.modules.web.service.mybatisplus.ICourseInfoClockSourcePlusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class CourseClockWebServiceImpl implements ICourseClockWebService {

    @Autowired
    private ICourseClockPlusService courseClockPlusService;

    @Autowired
    private ICourseInfoClockSourcePlusService clockSourcePlusService;
    @Override
    public List<String> getCourseClockClassNoList(String courseNo) {
        List<String> finalList = new ArrayList<>();
        LambdaQueryWrapper<CourseInfoClockSource> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CourseInfoClockSource::getCourseNo,courseNo);
        List<CourseInfoClockSource> list = clockSourcePlusService.list(wrapper);
        if (CollectionUtils.isEmpty(list)){
            return finalList;
        }
        return list.parallelStream().map(CourseInfoClockSource::getClassNo).distinct().collect(Collectors.toList());
    }

    @Override
    public List<CourseClock> queryExcellent(List<String> classList) {
        if (CollectionUtils.isEmpty(classList)){
            return null;
        }
        LambdaQueryWrapper<CourseClock> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(CourseClock::getClassNo,classList);
        wrapper.eq(CourseClock::getExcellent, ConstantUtils.Valid);
        return courseClockPlusService.list(wrapper);
    }
}
